<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>自定义promise</title>
</head>

<body>

</body>
<!-- <script src="./lib/Promise.js"></script> -->
<script src="./lib/Promise_class.js"></script>
<script>
  // const p = new Promise((resolve, reject) => {
  //   setTimeout(() => {
  //     // resolve(1);
  //     reject(2)
  //   }, 100);
  // }).then(
  //   value => {
  //     console.log('onResolved1()', value);
  //   },
  //   reason => {
  //     console.log('onRejected1()', reason);
  //     // return 3
  //     // throw 4
  //     return new Promise((resolve, reject) => reject(5))
  //   }
  // ).then(
  //   value => {
  //     console.log('onResolved2()', value);
  //   },
  //   reason => {
  //     console.log('onRejected2()', reason);
  //     throw 6
  //   }
  // ).catch(
  //   reason => {
  //     console.log('onRejected3()');
  //     return new Promise(() => { }) // 中断promise
  //   }
  // ).then(
  //   value => {
  //     console.log('onResolved4()', value);
  //   },
  //   reason => {
  //     console.log('onRejected4()', reason);
  //     throw 6
  //   }
  // )

  const p1 = Promise.resolve(2);
  const p2 = Promise.resolve(Promise.resolve(3));
  const p3 = Promise.resolve(Promise.reject(4));
  const p4 = new Promise((resolve) => {
    setTimeout(() => {
      resolve(5)
    }, 1000)
  })
  const p5 = Promise.reject(6)

  // p1.then(value => { console.log('p1', value) })
  // p2.then(value => { console.log('p2', value) })
  // p3.catch(reason => { console.log('p3', reason) })

  // const pAll = Promise.all([p4, 8, p1, p2])
  // pAll.then(
  //   values => {
  //     console.log('all onResolved()', values);
  //   },
  //   reason => {
  //     console.log('all onRejected()', reason);
  //   }
  // )

  // const pRace = Promise.race([p5, 7, p4, p1, p2, p3])
  // pRace.then(
  //   values => {
  //     console.log('race onResolved()', values);
  //   },
  //   reason => {
  //     console.log('race onRejected()', reason);
  //   }
  // )

  const p6 = Promise.resolveDelay(66, 2000);
  const p7 = Promise.rejectDelay(77, 3000);
  p6.then(value => { console.log('p6', value); })
  p7.catch(reason => { console.log('p7', reason); })


</script>

</html>